import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SArenaCrossBattleRecord } from "../../../../../Message/Public/SArenaCrossBattleRecord";
import { Cache } from "../../../cache/Cache";
import { PlayerUtil } from "../../common/util/PlayerUtil";
import { EBattleResult } from "../../../../../Message/Public/EBattleResult";
import { DateParser } from "../../../../common/tools/DateParser";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class ArenaCrossMyScheduleCellRenderer
    
    export  class ArenaCrossMyScheduleCellRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat1);
            var loc2=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6);
            this._tfName = ObjCreate.createTextField("", 0, 13, 180, 20, this, loc1);
            this._bmpVS = GlobalClass.getBitmap(ImagesConst.ArenaVS);
            this._bmpVS.x = 208;
            this._bmpVS.y = 1;
            this.addChild(this._bmpVS);
            this._btnEnemy = ObjCreate.createGButton("", 260, 6, 180, 28, this, "LinkButton");
            this._tfNoEnemy = ObjCreate.createTextField(Language.getString(44372), 260, 13, 180, 20, this, loc2);
            this._tfNoEnemy.visible = false;
            this._tfResult = ObjCreate.createTextField("", 440, 13, 80, 20, this, loc2);
            this._line = ObjCreate.createBg(10, 43, 520, 2, this, "SplitLine");
            this.addListeners();
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnEnemy.addEventListener(flash.events.MouseEvent.CLICK, this.onClickName);
            return;
        }

        /* internal  */onClickName(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._battleRecord) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetArenaCrossPlayerInfo, this._battleRecord.entityId));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "sarenacrossbattlerecord") 
            {
                this._battleRecord = arg1 as SArenaCrossBattleRecord;
                this.updateView();
            }
            return;
        }

        /* internal  */updateView(): void
        {
            this._tfName.text = Cache.instance.role.entityInfo.name;
            if (this._battleRecord.entityId.id == 0) 
            {
                this._tfNoEnemy.visible = true;
                this._btnEnemy.visible = false;
            }
            else 
            {
                this._btnEnemy.label = PlayerUtil.getProxyAndNameByEntityIdAndName(this._battleRecord.entityId, this._battleRecord.name);
                this._tfNoEnemy.visible = false;
                this._btnEnemy.visible = true;
            }
            if (this._battleRecord.result.value() != EBattleResult._EBattleResultNULL) 
            {
                if (this._battleRecord.result.value() != EBattleResult._EBattleResultWin) 
                {
                    this._tfResult.htmlText = Language.getString(44374);
                }
                else 
                {
                    this._tfResult.text = Language.getString(44373);
                }
            }
            else 
            {
                this._tfResult.text = DateParser.parse(this._battleRecord.battleDt, "hh: mm");
            }
            return;
        }

        /* internal */ /* var */_line: ScaleBitmap;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpVS: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnEnemy: GButton;

        /* internal */ /* var */_tfNoEnemy: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfResult: Object /* flash.text.TextField */;

        /* internal */ /* var */_battleRecord: SArenaCrossBattleRecord;
    }
